package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.ValidatePasswordBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.ValidatePasswordCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
/**
*验证传入密码是否和登录或交易密码相同
*FreeMaker Template自动生成代码
*/
@TestSuite
//passwordType 密码类型0-明文1- DES2- RSA Integer
public class Ts_ValidatePassword{
	private static ValidatePasswordBean validatepasswordBean;
	private static ValidatePasswordCall validatepasswordCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("验证传入密码是否和登录或交易密码相同");
	}

	@Before
	public void caseUp() {
		validatepasswordBean=new ValidatePasswordBean();
		validatepasswordCall=new ValidatePasswordCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(validatepasswordCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ValidatePassword_001() {
		Logger.start(true,"验证传入密码和登录密码相同,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
//			String tpwd="123abc";
//			JUserCallService.UpdateTradingPwd(uid, tpwd);
			validatepasswordBean.setPassword(cur.getLoginPassword());
			validatepasswordBean.setPasswordType(0);
			validatepasswordBean.setUserId(uid);;
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("300009", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(true,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_ValidatePassword_002() {
		Logger.start(true,"不传参数passwordType默认明文");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			validatepasswordBean.setPassword(cur.getLoginPassword());
//			validatepasswordBean.setPasswordType(0);
			validatepasswordBean.setUserId(uid);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("300009", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(true,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_ValidatePassword_003() {
		Logger.start(true,"不传参数password失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
//			validatepasswordBean.setPassword(cur.getLoginPassword());
			validatepasswordBean.setPasswordType(0);
			validatepasswordBean.setUserId(uid);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("100", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_ValidatePassword_004() {
		Logger.start(true,"不传参数userId失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			validatepasswordBean.setPassword(cur.getLoginPassword());
			validatepasswordBean.setPasswordType(0);
//			validatepasswordBean.setUserId(uid);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("100", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ValidatePassword_005() {
		Logger.start(true,"验证传入密码和交易相同,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String tpwd="123abc";
			JUserCallService.UpdateTradingPwd(uid, tpwd);
			validatepasswordBean.setPassword(tpwd);
			validatepasswordBean.setPasswordType(0);
			validatepasswordBean.setUserId(uid);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("300009", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(true,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ValidatePassword_006() {
		Logger.start(true,"验证传入密码和登入交易都不同,验证成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String tpwd="123abc";
			JUserCallService.UpdateTradingPwd(uid, tpwd);
			validatepasswordBean.setPassword(tpwd+1);
			validatepasswordBean.setPasswordType(0);
			validatepasswordBean.setUserId(uid);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("200", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ValidatePassword_007() {
		Logger.start(true,"Des加密验证传入密码和登录密码相同,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
//			String tpwd="123abc";
//			JUserCallService.UpdateTradingPwd(uid, tpwd);
			validatepasswordBean.setPassword(JUserCallService.getDesPwd(cur.getLoginPassword()));
			validatepasswordBean.setPasswordType(1);
			validatepasswordBean.setUserId(uid);;
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("300009", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(true,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ValidatePassword_008() {
		Logger.start(true,"Des加密验证传入密码和交易相同,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String tpwd="123abc";
			JUserCallService.UpdateTradingPwd(uid, tpwd);
			validatepasswordBean.setPassword(JUserCallService.getDesPwd(tpwd));
			validatepasswordBean.setPasswordType(1);
			validatepasswordBean.setUserId(uid);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("300009", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(true,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ValidatePassword_009() {
		Logger.start(true,"Des加密验证传入密码和登入交易都不同,验证成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String tpwd="123abc";
			JUserCallService.UpdateTradingPwd(uid, tpwd);
			validatepasswordBean.setPassword(JUserCallService.getDesPwd(tpwd+1));
			validatepasswordBean.setPasswordType(1);
			validatepasswordBean.setUserId(uid);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("200", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ValidatePassword_010() {
		Logger.start(true,"Rsa加密验证传入密码和登录密码相同,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
//			String tpwd="123abc";
//			JUserCallService.UpdateTradingPwd(uid, tpwd);
			validatepasswordBean.setPassword(JUserCallService.getRsaPwd(cur.getLoginPassword()));
			validatepasswordBean.setPasswordType(2);
			validatepasswordBean.setUserId(uid);;
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("300009", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(true,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ValidatePassword_011() {
		Logger.start(true,"Rsa加密验证传入密码和交易相同,成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String tpwd="123abc";
			JUserCallService.UpdateTradingPwd(uid, tpwd);
			validatepasswordBean.setPassword(JUserCallService.getRsaPwd(tpwd));
			validatepasswordBean.setPasswordType(2);
			validatepasswordBean.setUserId(uid);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("300009", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(true,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ValidatePassword_012() {
		Logger.start(true,"Rsa加密验证传入密码和登入交易都不同,验证成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			String tpwd="123abc";
			JUserCallService.UpdateTradingPwd(uid, tpwd);
			validatepasswordBean.setPassword(JUserCallService.getRsaPwd(tpwd+1));
			validatepasswordBean.setPasswordType(2);
			validatepasswordBean.setUserId(uid);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("200", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("true", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ValidatePassword_013() {
		Logger.start(true,"异常存量数据校验,失败");
		try {
			//异常存量数据?
			validatepasswordBean.setPassword("123456");
			validatepasswordBean.setPasswordType(0);
			validatepasswordBean.setUserId(413442);
			validatepasswordCall.setData(validatepasswordBean);
			validatepasswordCall.callService();			
			Logger.verifyEquals("198", validatepasswordCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("false", validatepasswordCall.getString("Success"), "验证Success");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithLoginPassword").getAsBoolean(),"验证repeatWithLoginPassword");
			Logger.verifyEquals(false,validatepasswordCall.getJsonObject().get("Result").getAsJsonObject().get("repeatWithTradingPassword").getAsBoolean(),"验证repeatWithTradingPassword");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}